package com.huarui.companypackage.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.ewaf.framework.dao.impl.BaseDaoImpl;
import org.springframework.orm.ibatis.SqlMapClientCallback;

import com.huarui.companypackage.dao.ICompanyPackageServiceDao;
import com.huarui.companypackage.model.CompanyPackageService;
import com.ibatis.sqlmap.client.SqlMapExecutor;

public class CompanyPackageServiceDaoImpl extends BaseDaoImpl implements ICompanyPackageServiceDao {

	@Override
	public void batchInsertPackageService(final List<CompanyPackageService> packageServices) {
		getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
			
			@Override
			public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
				executor.startBatch();
				int batch = 0;
				for (CompanyPackageService packageService : packageServices) {
					executor.insert(namespace + ".create", packageService);
					batch++;
					if (batch == 50) {
						executor.executeBatch();
						batch = 0;
					}
				}
				executor.executeBatch();
				return null;
			}
		});		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<CompanyPackageService> getPackageServiceByPackageId(Integer packageId) {
		return getSqlMapClientTemplate().queryForList(namespace+".getPackageServiceByPackageId", packageId);
	}

}
